import wepy from 'wepy'

export default class extends wepy.mixin {
  data = {
    active: 0,
    allOrderList: [],
    waitOrderList: [],
    finishOrderList: [],
  }
  onLoad() {
    this.getOrderList(this.active)
  }
  methods = {
    onTabChange(e) {
      this.active = e.detail.index
      this.getOrderList(this.active)
    }
  }
  async getOrderList(index) {
    var { data: res } = await wepy.get('/my/orders/all', { type: index + 1 })
    // 序列化  --没有数据
  /*   res.message.orders.forEach(x=>{
      x.order_detail=JSON.parse(x.order_detail)
    }) */
    if (res.meta.status != 200) return wepy.baseToast('没有数据--获取订单列表失败')
    if (index == 0) { this.allOrderList = res.message.orders }
    else if (index == 1) { this.waitOrderList = res.message.orders }
    else if (index == 2) { this.finishOrderList = res.message.orders }
    else { wepy.baseToast('数据请求错误') }
    this.$apply();

  }
}